import json
import uuid

from kpi.Kpi_service import kpiServiceApp
from bottle import run, Bottle
# from app.mapScatter import mapScatterApp
# from app.combine import combineApp
from app.DataService import dataServiceApp
from app.fileUpload import fileUploadServiceApp
from bottle import Bottle, request, response, template, static_file

app = Bottle()


# 处理跨域问题
@app.hook('before_request')
def validate():
    REQUEST_METHOD = request.environ.get('REQUEST_METHOD')

    HTTP_ACCESS_CONTROL_REQUEST_METHOD = request.environ.get('HTTP_ACCESS_CONTROL_REQUEST_METHOD')
    if REQUEST_METHOD == 'OPTIONS' and HTTP_ACCESS_CONTROL_REQUEST_METHOD:
        request.environ['REQUEST_METHOD'] = HTTP_ACCESS_CONTROL_REQUEST_METHOD


@app.hook('after_request')
def enable_cors():
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Headers'] = '*'
    response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'


if __name__ == '__main__':
    # 挂载路由
    # app.mount("/mapScatter",mapScatterApp)
    # app.mount("/combine",combineApp)
    app.mount("/getData", dataServiceApp)
    app.mount("/getKpiData", kpiServiceApp)

    app.mount("/file_upload", fileUploadServiceApp)
    # open 5000 port on 10.178.232.233
    app.run(host='0.0.0.0', port=8080, debug=True)





